﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SaunaServer.Controller.Communication;
using SaunaServer.Model.Network;
using SaunaServer.View;

namespace SaunaServerUnitTest
{
    [TestClass]
    public class UnitTestClientOptionForm
    {
        NetworkSetting networkSetting = null;
        private string CONFIG_DIR_FILE_NAME = @"G:\JCU_Y2_SP2\Software Engineering - CP2013\SourceCode\CommunicationServer\CommunicationServer\bin\Debug\SaunaConfig.ini";

        [TestMethod]
        public void TestReadNetworkSetting()
        {
            // Create Communication Manager
            CommunicationManager communicationManager = new CommunicationManager(new CommunicationServerForm());

            // Read Sauna configuration file and create network setting
            networkSetting = communicationManager.ReadConfigFileFromDirectory(CONFIG_DIR_FILE_NAME);
            Assert.IsNotNull(networkSetting);
        }

        [TestMethod]
        public void TestCreateOptionFormObject()
        {
            NetworkSetting networkSettingOriginal;

            TestReadNetworkSetting();

            networkSettingOriginal = networkSetting.Clone();

            ClientOptionForm clientOptionForm = new ClientOptionForm(networkSetting);            
            
            // Simulate OK button event
            clientOptionForm.UnitTestButtonOkClick();

            TestReadNetworkSetting();

            Assert.AreEqual(networkSetting.DBDatabaseName, networkSettingOriginal.DBDatabaseName);
            Assert.AreEqual(networkSetting.DBHostAddress, networkSettingOriginal.DBHostAddress);
            Assert.AreEqual(networkSetting.DBPassword, networkSettingOriginal.DBPassword);
            Assert.AreEqual(networkSetting.DBUserName, networkSettingOriginal.DBUserName);
            Assert.AreEqual(networkSetting.FtpHostAddress, networkSettingOriginal.FtpHostAddress);
            Assert.AreEqual(networkSetting.FtpLocalDirectory, networkSettingOriginal.FtpLocalDirectory);
            Assert.AreEqual(networkSetting.FtpPassword, networkSettingOriginal.FtpPassword);
            Assert.AreEqual(networkSetting.FtpPortNumber, networkSettingOriginal.FtpPortNumber);
            Assert.AreEqual(networkSetting.FtpServerDirectory, networkSettingOriginal.FtpServerDirectory);
            Assert.AreEqual(networkSetting.FtpSsl, networkSettingOriginal.FtpSsl);
            Assert.AreEqual(networkSetting.TcpHostAddress, networkSettingOriginal.TcpHostAddress);
            Assert.AreEqual(networkSetting.TcpPortNumber, networkSettingOriginal.TcpPortNumber);
            Assert.AreEqual(networkSetting.TcpSsl, networkSettingOriginal.TcpSsl);
            Assert.AreEqual(networkSetting.LogFileDirectory, networkSettingOriginal.LogFileDirectory);
        }
    }
}